# 学生数据
students = []


# 菜单函数显示
def show_menu():
    print("--------------------")
    print("1:添加学生")
    print("2:删除学生")
    print("3:修改学生")
    print("4:查询学生")
    print("5:显示所有学生")
    print("6:退出系统")
    print("--------------------")
    print("请输入一个功能ID")


def operator(sel_id):
    if sel_id == '1':
        add_stu()
    elif sel_id == '2':
        del_stu()
    elif sel_id == '3':
        change_stu()
    elif sel_id == '4':
        query_stu()
    elif sel_id == '5':
        show_all_stu()
    elif sel_id == '6':
        quiet_stu()


def add_stu():
    stu_id = input("请输入学号:")
    stu_name = input("请输入姓名:")
    stu_age = input("请输入年龄:")
    students.append({'id': stu_id, 'name': stu_name, 'age': stu_age})


def del_stu():
    stu_id = input("请输入需要删除的学号:")
    if isStudent_id_exist(stu_id):
        for i in students:
            if i['id'] == stu_id:
                students.remove(i)
                print("数据删除成功")
    else:
        print("输入的学生号不存在")


def change_stu():
    stu_id = input("请输入需要修改学生的学号:")
    if isStudent_id_exist(stu_id):
        for i in students:
            if i['id'] == stu_id:
                stu_id = input("请输入学号:")
                stu_name = input("请输入姓名:")
                stu_age = input("请输入年龄:")
                i['id'] = stu_id
                i['name'] = stu_name
                i['age'] = stu_age
                print("修改成功")
                break
    else:
        print("输入的学生号不存在")


def query_stu():
    stu_id = input("请输入查询学生的学号:")
    if isStudent_id_exist(stu_id):
        for x in students:
            if x['id'] == stu_id:
                print('学号: ' + x['id'] + '  姓名: ' + x['name'] + '  年龄: ' + x['age'])
    else:
        print("输入的学生号不存在")


def show_all_stu():
    show_students_info()


def quiet_stu():
    print("退出系统")
    exit()


# 判断学生ID是存在
def isStudent_id_exist(stu_id):
    b = False
    for i in students:
        if i['id'] == stu_id:
            b = True
    return b


def show_students_info():
    if len(students) == 0:
        print('没有学生信息可显示')
    else:
        for x in students:
            print('学号: ' + x['id'] + '  姓名: ' + x['name'] + '  年龄: ' + x['age'])


def main():
    while True:
        show_menu()
        operator(input())


main()
